package com.csdn.leon.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.csdn.leon.model.BlogModel;
import com.csdn.leon.model.CloumnModel;
import com.csdn.leon.model.Person;
import com.csdn.leon.base.R;

public class CloumnDetailAdapter extends BaseAdapter{
	private List<CloumnModel> list;

	private Person person;

	LayoutInflater inflate;

	private Context context;

	private final int TYPE1 = 1;
	private final int TYPE2 = 2;

	public CloumnDetailAdapter(Context context) {
		this.context = context;
		inflate = LayoutInflater.from(context);
		if (list == null) {
			list = new ArrayList<CloumnModel>();
		}
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	// @Override
	// public int getItemViewType(int position) {
	// if (position == 0) {
	// return TYPE1;
	// } else {
	// return TYPE2;
	// }
	// }
	//
	// @Override
	// public int getViewTypeCount() {
	// return 2;
	// }

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		UserHolder userHolder = null;
		BlogHolder holder = null;
		CloumnModel model = list.get(position);
		// int type = getItemViewType(position);
		if (convertView == null) {
			holder = new BlogHolder();
			convertView = inflate.inflate(R.layout.list_cell_cloumn, null);
			holder.title_tv = (TextView) convertView
					.findViewById(R.id.tv_title);
			holder.content_tv = (TextView) convertView
					.findViewById(R.id.tv_description);
			holder.sorce_tv = (TextView) convertView
					.findViewById(R.id.tv_source);
			convertView.setTag(holder);

		} else {
			holder = (BlogHolder) convertView.getTag();
		}

		holder.title_tv.setText(model.getTitle());
		holder.content_tv.setText(model.getContent());
		holder.sorce_tv.setText(model.getDate());

		return convertView;
	}

	public List<CloumnModel> getList() {
		return list;
	}

	public void setList(List<CloumnModel> list) {
		this.list = list;
		notifyDataSetChanged();
	}

	public void addAllList(List<CloumnModel> list) {
		this.list.addAll(list);
		notifyDataSetChanged();
	}

	public Person getPerson() {
		return person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}

	private class UserHolder {
		private ImageView bgImg;
		private ImageView userImg;
		private TextView username;
	}

	private class BlogHolder {
		private TextView title_tv;
		private TextView content_tv;
		private TextView sorce_tv;
	}
}
